package as3.component.support
{
	import flash.events.EventDispatcher;

	public class DataProvider extends EventDispatcher
	{
		
		private var _list:Array = [];
		
		public function DataProvider()
		{
			
		}
		
		public function addItem(item:Object):void
		{
			if (getItemIndex(item) == -1) {
				_list.push(item);
			}
		}
		
		public function addItems(ary:Array):void
		{
			if (!ary) return;
			_list = _list.concat(ary);
		}
		
		public function getItemAt(index:uint):Object
		{
			if (index >= length) return null;
			else return _list[index];
		}
		
		public function getItemIndex(item:Object):int
		{
			if (item == null) return -1;
			return _list.indexOf(item);
		}
		
		public function removeItem(item:Object):Object
		{
			if (item == null) return -1;
			var index:int = getItemIndex(item);
			if (index == -1) return null;
			else {
				return _list.splice(index, 1)[0];
			}
		}
		
		public function removeItemAt(index:uint):Object
		{
			if (index >= length) return null;
			else return _list.splice(index, 1)[0];
		}
		
		public function get list():Array
		{
			return _list;
		}
		
		public function get length():int
		{
			return _list.length;
		}
		
	}
}